let proxyObj = {};
const CompressionPlugin = require("compression-webpack-plugin");
proxyObj['/ws'] = {
    ws: true,
    // target: "ws://localhost:8081/"
    target: "ws://124.220.15.11:8081/"
};
proxyObj['/'] = {      //斜杠存疑
    ws: false,
    // target: 'http://localhost:8081/',
    target: 'http://124.220.15.11:8081/',
    // target: 'http://localhost:80/nginx/',
    changeOrigin: true,
    pathRewrite: {
        '^/': ''
    }
}

const dev = process.env.NODE_ENV === 'development'

module.exports = {
    devServer: {  //devServer.proxy 可以是一个指向开发环境 API 服务器的字符串；这会告诉开发服务器将任何未知请求 (没有匹配到静态文件的请求) 代理到target的地址
        host: '0.0.0.0',
        port: 8080,
        proxy: proxyObj
    },
    configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            return {
                plugins: [
                    new CompressionPlugin({
                        test: /\.js$|\.html$|\.css/,
                        threshold: 1024,
                        deleteOriginalAssets: false
                    })
                ]
            }
        }
        else if (process.env.NODE_ENV=="development"){
            return{
                devtool:"source-map",
                plugins: [
                    new CompressionPlugin({
                        test: /\.js$|\.html$|\.css/,
                        threshold: 1024,
                        deleteOriginalAssets: false
                    })
                ]
            }
        }
    }
}